#使用pyMySQL实现登录功能
from db_utils import D


def lo(b_name,price):
    #定义sql
    sql = "select * from books where b_name = %s and price = %s"
    p = [b_name,price]
    #获取dbutils对象
    db = D("test")
    #执行sql
    result =db.selectOne(sql,p)
    if result ==None:
        return {"mas": "用户名或密码错误"}
    else:
        return {"mas":"登陆成功"}

def regist(b_name,price):
    sql = "insert into books(b_name,price) values(%s,%s)"
    p = [b_name, price]
    # 获取dbutils对象
    db = D("test")
    result =db.update(sql,p)
    if result >0:
        return {"mas":"注册成功"}
    else:
        return {"mas": "注册失败"}

if __name__ == '__main__':
    print(lo("东吴旧事",15))
    print(regist("东吴",150))